<template>
	<view class="content">
		<u-navbar title="发展中" height="88rpx" :placeholder='true' left-icon-color="#fff"
			titleStyle='color:#fff;font-size:32rpx' left-icon-size="32rpx" bg-color="#FF594D" :autoBack="true">
		</u-navbar>
		<view class="tags_content">
			<template v-for="(item,index) in userData">
				<view class="tags_item" :key="index">
					<view class="left">
						<view class="tags">

						</view>
						<view class="name">
							{{item.name}}
						</view>
						<view class="tel">
							<text>{{item.phone?item.phone:'暂无手机号'}}</text>
							<!-- <image src="/static/images/factionalism/编辑@2x.png" mode=""></image> -->
						</view>
						<!-- <view class="open" @click="navigateTo('/pages_spell/pages/add-developing/add-developing?id='+item.id)"> -->
						<view class="open" @click="openMember(item)">
							开卡
						</view>
					</view>
					<view class="bottom_time">
						<view class="time">
							{{item.createTime}}
						</view>
						<view class="del" @click="userId=item.id;show=true">
							删除
						</view>
					</view>
				</view>
			</template>
		</view>

		<u-modal :show="show" :showCancelButton='true' @cancel="userId='';show=false" @confirm="confirm" :title="title"
			confirmColor='red'>
			<view class="slot-content">
				<rich-text :nodes="'是否删除'"></rich-text>
			</view>
		</u-modal>
		<view class="bottom">
			<view class="left" @click="navigateTo('/pages_spell/pages/add-developing/add-developing')">
				添加发展会员
			</view>
		</view>
	</view>
</template>

<script>
	import {
		userList,
		fmemberlist,
		addMember,
		delfmember
	} from '../../../api/employee.js'
	export default {
		data() {
			return {
				titleStyle: {
					color: '#fff'
				},
				userData: [],
				userId: '',
				show: false
			};
		},
		created() {
			this.getUserList({
				isF: this.$store.state.employeeInfo.userId
			})
		},
		methods: {
			confirm() {
				this.delFMember(this.userId)
			},
			async delFMember(id) {
				const res = await delfmember(id)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.show = false
				this.userId = ''
				this.getUserList({
					isF: this.$store.state.employeeInfo.userId
				})
			},
			async newlyAddMember(data) {
				const res = await addMember(data)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: res.msg ?? '失败',
						icon: 'none'
					})
					return
				}
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			},
			openMember(data) {
				this.newlyAddMember({
					userId: data.id,
					employeeId: data.isF,
					employeeName: this.$store.state.employeeInfo.userName,
					name: data.name,
					phone: data.phone,
					birthday: '1970-1-1',
					sex: data.sex ?? 1,
					enable: 1,
					birthdayMonth: '1',
					memberType: 1,
					"memberybDTO": {
						"appId": "",
						"customerInfo": {
							"categoryName": "",
							"number": "",
							"name": "",
							"phone": "",
							"birthday": "",
							"qq": "",
							"email": "",
							"address": "",
							"remarks": "",
							"point": 0.00,
							"discount": 0.00,
							"balance": 0.00,
							"enable": 0,
							"onAccount": 0,
							"expiryDate": "",
							"password": "",
							"sex": 0,
							"lunarBirthday": "",
							"totalPoint": 0.00,
							"creditLimit": 0.00,
							"creditPeriod": 0.00,
							"nickName": ""
						}
					}
				})
			},
			async getUserList(data) {
				const res = await fmemberlist(data)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				this.userData = res.rows
			},
			navigateTo(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f3f3f3;
		min-height: 100vh;
		padding-bottom: 120rpx;
		box-sizing: border-box;

		.tags_content {
			padding: 20rpx;

			.tags_item {
				padding: 24rpx 20rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #777777;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-bottom: 20rpx;

				.left {
					display: flex;
					align-items: center;

					.name {
						// padding: 0 50rpx;
						width: 220rpx;
					}

					.tel {
						display: flex;
						width: 206rpx;
						align-items: center;
						justify-content: space-between;

						image {
							width: 32rpx;
							margin-left: 20rpx;
							height: 32rpx;
						}
					}

					.open {
						width: 120rpx;
						height: 44rpx;
						border-radius: 6rpx;
						font-size: 20rpx;
						color: #FFFFFF;
						line-height: 44rpx;
						text-align: center;
						background-color: #FF594D;
						margin-left: 128rpx;
					}
				}

				.bottom_time {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-top: 20rpx;

					.del {
						color: #FF594D;
						padding-right: 27rpx;
					}
				}
			}
		}

		.bottom {
			width: 752rpx;
			height: 120rpx;
			background-color: #FFFFFF;
			position: fixed;
			left: 0;
			bottom: 0;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left,
			.right {
				flex: 1;
				height: 120rpx;
				background: #FF594D;
				text-align: center;
				line-height: 120rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				color: #FFFFFF;
			}

			.left {}

			.right {}
		}
	}
</style>